//
//  JSLLoanDetialTotalCell.m
//  JingleSpeedLoan
//
//  Created by 宋质彬 on 2018/8/2.
//  Copyright © 2018年 宋质彬. All rights reserved.
//

#import "JSLLoanDetialTotalCell.h"
@interface JSLLoanDetialTotalCell ()
@property (nonatomic , weak) UILabel *titleLab;
@property (nonatomic , weak) UILabel *titleSrcLab;
@property (nonatomic , weak) UIImageView *imageArrow;
@property (nonatomic , weak) UIButton *arrowButton;
@end
@implementation JSLLoanDetialTotalCell

#pragma mark - init
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        
        [self setUpAllChildView];
        
    }
    return self;
}

- (void)setInfo:(NSDictionary *)info {
    _info = info;
//
//    subSrc = "3\U4e2a\U6708";
//    title = "\U671f\U9650";
    
    self.titleLab.text = info[@"title"];
    self.titleSrcLab.text = info[@"subSrc"];
}

#pragma mark - 配置视图
- (void)layoutSubviews{
    [super layoutSubviews];
    [self configFrame];
}

- (void)configFrame{
 

    CGSize titleSize = [self.titleLab.text sizeWithAttributes:@{NSFontAttributeName : self.titleLab.font}];
    self.titleLab.frame = CGRectMake(40*AutoSizeScaleXX, 0*AutoSizeScaleXX, titleSize.width, CGRectGetHeight(self.contentView.frame));
    
    
    if ([self.info[@"subSrc"] hasSuffix:@"月"]) {
        self.imageArrow.frame = CGRectMake(CGRectGetWidth(self.contentView.frame) - 40*AutoSizeScaleXX - 10*AutoSizeScaleXX, self.titleLab.height*0.5-10*AutoSizeScaleXX*0.5, 10*AutoSizeScaleXX, 10*AutoSizeScaleXX);
    
        CGSize titleSrcSize = [self.titleSrcLab.text sizeWithAttributes:@{NSFontAttributeName : self.titleSrcLab.font}];
        self.titleSrcLab.frame = CGRectMake(self.imageArrow.right -10*AutoSizeScaleXX -titleSrcSize.width, 0, titleSrcSize.width, self.titleLab.height);
        
        self.arrowButton.frame = CGRectMake(CGRectGetWidth(self.contentView.frame)- 200*AutoSizeScaleXX , 0, 200*AutoSizeScaleXX, self.titleLab.height);
//        self.arrowButton.backgroundColor = [UIColor redColor];

    }else {
        self.imageArrow.frame = CGRectZero;
        CGSize titleSrcSize = [self.titleSrcLab.text sizeWithAttributes:@{NSFontAttributeName : self.titleSrcLab.font}];
        
        NSLog(@"%@---%f",NSStringFromCGSize(titleSrcSize),CGRectGetWidth(self.contentView.frame));
        self.titleSrcLab.frame = CGRectMake(CGRectGetWidth(self.contentView.frame) - 40*AutoSizeScaleXX-titleSrcSize.width, 0, titleSrcSize.width, self.titleLab.height);
    }
    
    
    
    
}
- (void)setUpAllChildView{
    self.titleLab = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"期限" font:LIGHT_FONT(12) textColor:[@"#999999" hexStringToColor] textAlignment:NSTextAlignmentLeft SuperView:self.contentView];
    
    self.titleSrcLab = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"250000.00" font:LIGHT_FONT(12) textColor:[@"#666666" hexStringToColor] textAlignment:NSTextAlignmentLeft SuperView:self.contentView];

    self.imageArrow = [JSLKitFactory jsl_imageViewWithFrame:CGRectZero imageName:@"detial-arrow" superView:self.contentView];
    
    self.arrowButton = [JSLKitFactory jsl_imageButtonWithFrame:CGRectZero superView:self.contentView setImage:nil setBackImage:nil target:self action:@selector(clickAction:)];
    
    [self.contentView bringSubviewToFront:self.arrowButton];
    
    
}

- (void)clickAction:(UIButton *)sender {
    if ([self.deleagete respondsToSelector:@selector(clickArrowButtion)]) {
        [self.deleagete clickArrowButtion];
    }
    
}

#pragma mark - 创建cell
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
    static NSString * ID = @"JSLLoanDetialTotalCell";
    id cell = [tableView dequeueReusableCellWithIdentifier:ID ];
    
    if (cell == nil) {
        cell = [[self alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    
    return cell;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}


@end
